if SERVER then

--[[=========================================================
	TABLE DELETION FUNCTIONS
=========================================================]]--

--[[-----------------------------------------------------]]--
--	Player Stats
--[[-----------------------------------------------------]]--
local function DropPlayerStatsTable()

	--	Skip if table does not exist
	if not sql.TableExists( "PlayerStats" ) then
		DEBUG:Msg( "Skipped deletion of 'PlayerStats' because it doesn't exist", "DropPlayerStatsTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE PlayerStats"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'PlayerStats' table ...", "DropPlayerStatsTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	User Info
--[[-----------------------------------------------------]]--
local function DropUserInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "UserInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'UserInfo' because it doesn't exist", "DropUserInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE UserInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'UserInfo' table ...", "DropUserInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Player Info
--[[-----------------------------------------------------]]--
local function DropPlayerInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "PlayerInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'PlayerInfo' because it doesn't exist", "DropPlayerInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE PlayerInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'PlayerInfo' table ...", "DropPlayerInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Team Info
--[[-----------------------------------------------------]]--
local function DropTeamInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "TeamInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'TeamInfo' because it doesn't exist", "DropTeamInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE TeamInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'TeamInfo' table ...", "DropTeamInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Inventory Object
--[[-----------------------------------------------------]]--
local function DropInventoryObjectTable()

	--	Skip if table does not exist
	if not sql.TableExists( "InventoryObject" ) then
		DEBUG:Msg( "Skipped deletion of 'InventoryObject' because it doesn't exist", "DropInventoryObjectTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE InventoryObject"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'InventoryObject' table ...", "DropInventoryObjectTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Player Loadout
--[[-----------------------------------------------------]]--
local function DropPlayerLoadoutTable()

	--	Skip if table does not exist
	if not sql.TableExists( "PlayerLoadout" ) then
		DEBUG:Msg( "Skipped deletion of 'PlayerLoadout' because it doesn't exist", "DropPlayerLoadoutTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE PlayerLoadout"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'PlayerLoadout' table ...", "DropPlayerLoadoutTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Loadout Inventory
--[[-----------------------------------------------------]]--
local function DropLoadoutInventoryTable()

	--	Skip if table does not exist
	if not sql.TableExists( "LoadoutInventory" ) then
		DEBUG:Msg( "Skipped deletion of 'LoadoutInventory' because it doesn't exist", "DropLoadoutInventoryTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE LoadoutInventory"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'LoadoutInventory' table ...", "DropLoadoutInventoryTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Loadout Position Link
--[[-----------------------------------------------------]]--
local function DropLoadoutPositionLinkTable()

	--	Skip if table does not exist
	if not sql.TableExists( "LoadoutPositionLink" ) then
		DEBUG:Msg( "Skipped deletion of 'LoadoutPositionLink' because it doesn't exist", "DropLoadoutPositionLinkTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE LoadoutPositionLink"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'LoadoutPositionLink' table ...", "DropLoadoutPositionLinkTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Loadout
--[[-----------------------------------------------------]]--
local function DropLoadoutTable()

	--	Skip if table does not exist
	if not sql.TableExists( "Loadout" ) then
		DEBUG:Msg( "Skipped deletion of 'Loadout' because it doesn't exist", "DropLoadoutTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE Loadout"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'Loadout' table ...", "DropLoadoutTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Loadout Position
--[[-----------------------------------------------------]]--
local function DropLoadoutPositionTable()

	--	Skip if table does not exist
	if not sql.TableExists( "LoadoutPosition" ) then
		DEBUG:Msg( "Skipped deletion of 'LoadoutPosition' because it doesn't exist", "DropLoadoutPositionTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE LoadoutPosition"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'LoadoutPosition' table ...", "DropLoadoutPositionTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Inventory
--[[-----------------------------------------------------]]--
local function DropInventoryTable()

	--	Skip if table does not exist
	if not sql.TableExists( "Inventory" ) then
		DEBUG:Msg( "Skipped deletion of 'Inventory' because it doesn't exist", "DropInventoryTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE Inventory"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'Inventory' table ...", "DropInventoryTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Object Info
--[[-----------------------------------------------------]]--
local function DropObjectInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "ObjectInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'ObjectInfo' because it doesn't exist", "DropObjectInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE ObjectInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'ObjectInfo' table ...", "DropObjectInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Weapon Firemode
--[[-----------------------------------------------------]]--
local function DropWeaponFiremodeTable()

	--	Skip if table does not exist
	if not sql.TableExists( "WeaponFiremode" ) then
		DEBUG:Msg( "Skipped deletion of 'WeaponFiremode' because it doesn't exist", "DropWeaponFiremodeTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE WeaponFiremode"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'WeaponFiremode' table ...", "DropWeaponFiremodeTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Firemode
--[[-----------------------------------------------------]]--
local function DropFiremodeTable()

	--	Skip if table does not exist
	if not sql.TableExists( "Firemode" ) then
		DEBUG:Msg( "Skipped deletion of 'Firemode' because it doesn't exist", "DropFiremodeTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE Firemode"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'Firemode' table ...", "DropFiremodeTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Weapon
--[[-----------------------------------------------------]]--
local function DropWeaponTable()

	--	Skip if table does not exist
	if not sql.TableExists( "Weapon" ) then
		DEBUG:Msg( "Skipped deletion of 'Weapon' because it doesn't exist", "DropWeaponTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE Weapon"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'Weapon' table ...", "DropWeaponTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Object Type
--[[-----------------------------------------------------]]--
local function DropObjectTypeTable()

	--	Skip if table does not exist
	if not sql.TableExists( "ObjectType" ) then
		DEBUG:Msg( "Skipped deletion of 'ObjectType' because it doesn't exist", "DropObjectTypeTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE ObjectType"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'ObjectType' table ...", "DropObjectTypeTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	View Transform Info
--[[-----------------------------------------------------]]--
local function DropViewTransformInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "ViewTransformInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'ViewTransformInfo' because it doesn't exist", "DropViewTransformInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE ViewTransformInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'ViewTransformInfo' table ...", "DropViewTransformInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Damage Info
--[[-----------------------------------------------------]]--
local function DropDamageInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "DamageInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'DamageInfo' because it doesn't exist", "DropDamageInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE DamageInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'DamageInfo' table ...", "DropDamageInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Activity Info
--[[-----------------------------------------------------]]--
local function DropActivityInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "ActivityInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'ActivityInfo' because it doesn't exist", "DropActivityInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE ActivityInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'ActivityInfo' table ...", "DropActivityInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[-----------------------------------------------------]]--
--	Sound Info
--[[-----------------------------------------------------]]--
local function DropSoundInfoTable()

	--	Skip if table does not exist
	if not sql.TableExists( "SoundInfo" ) then
		DEBUG:Msg( "Skipped deletion of 'SoundInfo' because it doesn't exist", "DropSoundInfoTable" )
		return true
	end
	
	--	Prepare the query
	local query			= "DROP TABLE SoundInfo"
	
	--	Debug output
	DEBUG:Msg( "Deleting 'SoundInfo' table ...", "DropSoundInfoTable" )
	
	--	Execute query
	return sql.Query( query )
end

--[[=========================================================
	GAMEMODE FUNCTIONS
=========================================================]]--

--[[-----------------------------------------------------]]--
--	Deletes the contents of the whole database
--[[-----------------------------------------------------]]--
sql.DropDataBase		= function()

	--	Variables
	local result		= true
	
	--	Drop tables
	result = result		&& ( DropPlayerStatsTable()			!= false )
	result = result		&& ( DropUserInfoTable()			!= false )
	result = result		&& ( DropPlayerInfoTable()			!= false )
	result = result		&& ( DropTeamInfoTable()			!= false )
	result = result		&& ( DropInventoryObjectTable()		!= false )
	result = result		&& ( DropPlayerLoadoutTable()		!= false )
	result = result		&& ( DropLoadoutInventoryTable()	!= false )
	result = result		&& ( DropLoadoutPositionLinkTable()	!= false )
	result = result		&& ( DropLoadoutTable()				!= false )
	result = result		&& ( DropLoadoutPositionTable()		!= false )
	result = result		&& ( DropInventoryTable()			!= false )
	result = result		&& ( DropObjectInfoTable()			!= false )
	result = result		&& ( DropWeaponFiremodeTable()		!= false )
	result = result		&& ( DropFiremodeTable()			!= false )
	result = result		&& ( DropWeaponTable()				!= false )
	result = result		&& ( DropObjectTypeTable()			!= false )
	result = result		&& ( DropViewTransformInfoTable()	!= false )
	result = result		&& ( DropDamageInfoTable()			!= false )
	result = result		&& ( DropActivityInfoTable()		!= false )
	result = result		&& ( DropSoundInfoTable()			!= false )
	
	--	Debug output - error
	if not result then
		DEBUG:ErrMsg( "Error while trying to drop the database. Last error: " .. sql.LastError(), "GM.DropDataBase" )
		
	--	Debug output - success
	else
		DEBUG:Msg( "The database has been successfully dropped !", "GM.DropDataBase" )
	end
	
	--	Return the result
	return result
end

end